package com.ruoyi.procured.mapper;

import java.util.List;
import java.util.Map;

import com.ruoyi.common.core.domain.ProcuredOrders;
import com.ruoyi.common.core.domain.OrdersProduct;
import com.ruoyi.procured.domain.vo.ArrivedQuantityDetailsVO;
import com.ruoyi.procured.domain.vo.OrdersProductDTO;
import org.apache.ibatis.annotations.MapKey;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Param;
import org.springframework.web.bind.annotation.PathVariable;


/**
 * 采购订单Mapper接口
 * 
 * @author ruoyi
 * @date 2023-11-15
 */
@Mapper
public interface ProcuredOrdersMapper 
{
    /**
     * 查询采购订单
     * 
     * @param ordersId 采购订单主键
     * @return 采购订单
     */
    public ProcuredOrders selectProcuredOrdersByOrdersId(Long ordersId);

    /**
     * 查询采购订单列表
     * 
     * @param procuredOrders 采购订单
     * @return 采购订单集合
     */
    public List<ProcuredOrders> selectProcuredOrdersList(ProcuredOrders procuredOrders);

    /**
     * 查询采购订单列表，查询5条
     * @param procuredOrders
     * @return
     */
    public List<ProcuredOrders> selectProcuredOrdersByList(ProcuredOrders procuredOrders);

    /**
     * 新增采购订单
     * 
     * @param procuredOrders 采购订单
     * @return 结果
     */
    public int insertProcuredOrders(ProcuredOrders procuredOrders);

    /**
     * 修改采购订单
     * 
     * @param procuredOrders 采购订单
     * @return 结果
     */
    public int updateProcuredOrders(ProcuredOrders procuredOrders);

    /**
     * 删除采购订单
     * 
     * @param ordersId 采购订单主键
     * @return 结果
     */
    public int deleteProcuredOrdersByOrdersId(Long ordersId);

    /**
     * 批量删除采购订单
     * 
     * @param ordersIds 需要删除的数据主键集合
     * @return 结果
     */
    public int deleteProcuredOrdersByOrdersIds(Long[] ordersIds);

    /**
     * 批量删除采购订单商品
     * 
     * @param ordersIds 需要删除的数据主键集合
     * @return 结果
     */
    public int deleteOrdersProductByOrdersIds(Long[] ordersIds);
    
    /**
     * 批量新增采购订单商品
     * 
     * @param ordersProductList 采购订单商品列表
     * @return 结果
     */
    public int batchOrdersProduct(List<OrdersProduct> ordersProductList);
    

    /**
     * 通过采购订单主键删除采购订单商品信息
     * 
     * @param ordersId 采购订单ID
     * @return 结果
     */
    public int deleteOrdersProductByOrdersId(Long ordersId);

    /**
     * 查询要撤销下单的采购单号
     * @param planId
     * @return
     */
    public List<ProcuredOrders> selectProcuredOrdersPlanId(Long planId);

    /**
     * 删除撤销的数据
     * @param ordersNumbers
     * @return
     */
    public int deleteProcuredOrdersByOrdersNumber(@Param("ordersNumbers") String[] ordersNumbers);
    public int deleteOrdersProductByOrdersNumber(@Param("ordersNumbers") String[] ordersNumbers);

    /**
     * 入库选择的采购单号数据
     * @param ordersIds
     * @return
     */
    public List<ProcuredOrders> selectByOrdersId(@Param("ordersIds") Long[] ordersIds);

    /**
     * 确认入库，这条产品是否还显示
     * @param selectedStatus
     * @param ordersId
     * @param proNo
     * @return
     */
    public int updateOrdersProductSelectedStatus(@Param("selectedStatus") String selectedStatus,@Param("ordersId") Long ordersId,@Param("proNo") String proNo);

    /**
     * 查询总入库数
     * @param ordersId
     * @return
     */
    public int updateInboundNumber(@Param("ordersId") Long ordersId);

    /**
     * 修改入库状态以及入库数量
     * @param procuredOrders
     * @return
     */
    public int updateInboundStatus(ProcuredOrders procuredOrders);

    /**
     * 通过计划单号来查询供应商、采购人员
     * @param ordersId
     * @return
     */
    public ProcuredOrders selectOrdersNumber(@PathVariable("ordersId") String ordersId);

    /**
     * 添加快递单号
     * @param procuredOrders
     * @return
     */
    public int updateExpressNumber(ProcuredOrders procuredOrders);


    /**
     * 根据采购计划id查询所有的采购订单id
     * @param planId
     */
    List<Long> selectPlanOrderNumber(@Param("planId") Long planId);

    /**
     * 根据采购计划id查询所有采购订单信息
     * @param procuredOrder
     * @return
     */
    public List<ProcuredOrders> selectByPlanId(ProcuredOrders procuredOrder);

    /**
     * 根据采购订单号查询出对应的入库数量
     * @return
     */
    ProcuredOrders selectInboundNumber(@Param("ordersId") String ordersId);

    /**
     * 查询当天最新的批次号
     * @param currentDate
     * @return
     */
	String getLatestBatchNumber(@Param("currentDate") String currentDate);

    /**
     * 查询库存待到货量详细
     * @param vo
     * @return
     */
	List<ArrivedQuantityDetailsVO> getArrivedQuantityDetails(@Param("vo")ArrivedQuantityDetailsVO vo);

    /**
     *  根据主键查询出对应的采购订单数据
     * @param orderId
     * @return
     */
    ProcuredOrders selectByOrderId(@Param("orderId") Long orderId);

    /**
     *  根据采购计划id和产品id查询采购订单数据
     * @return
     */
    List<ProcuredOrders> selectByOrderIds(@Param("planIds") List<Long> planIds,@Param("productId") Long productId);
    /**
     * 查询该申请的采购订单数据（商品信息，入库，出库信息）
     * @param ordersId
     * @return
     */
    List<OrdersProductDTO> selectOrdersProductListByOrdersId(@Param("orderId")  Long ordersId);

    /**
     * 修改采购订单和采购商品样式
     * @param planIds
     * @param productId
     * @return
     */
	int updateStyleClass(@Param("planIds") List<Long> planIds,@Param("productId") Long productId);

    /**
     * 根据采购单号查询采购订单信息
     * @param procuredOrderNumber
     * @return
     */
    ProcuredOrders selectByOrdersNumber(@Param("number") String procuredOrderNumber);

    int  getProcuredOrderStatus(Long procuredOrderId);

    /**
     * 取消采购订单样式
     * @return
     */
    int updateCancelStyleClass(@Param("procuredOrderNumber") String procuredOrderNumber);

    /**
     * 取消采购订单样式
     * @return
     */
    int updateCancelStyleClassByOrdersId(@Param("ordersId") Integer ordersId);

    /**
     * 修改采购订单状态
     * @param status
     * @return
     */
    int updateStatus(@Param("ordersId") String ordersId, @Param("status") String status);
    /**
     * 汇总未处理的驳回申请记录
     * @param params
     * @return
     */
    @MapKey("orderId")
    List<Map<String, Object>>  countGroupByOrderIds(Map<String, Object> params);


    /**
     * 查询未被收货过的采购订单
     * @param procuredOrders
     * @return
     */
//    List<ProcuredOrders> selectProcuredUnreceivedOrders(ProcuredOrders procuredOrders);
}
